package com.cx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cx.entity.Statistic;
import com.cx.mapper.StatisticMapper;
import com.cx.service.StatisticService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class StatisticServiceImpl extends ServiceImpl<StatisticMapper, Statistic> implements StatisticService {
    public void updateByArticleId(Integer articleId) {
        QueryWrapper<Statistic> statisticQueryWrapper = new QueryWrapper<>();
        statisticQueryWrapper.eq("article_id",articleId);
        Statistic statistic = this.baseMapper.selectOne(statisticQueryWrapper);
        statistic.setHits(statistic.getHits()+1);
        this.baseMapper.updateById(statistic);
    }

}
